package com.yashi.springmvcjbpm.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yashi.springmvcjbpm.dao.impl.StaffDAOImpl;
import com.yashi.springmvcjbpm.entity.Staff;

@Controller
public class EditUserController {
	
	@RequestMapping("editUser")
	public String goEdit(HttpServletRequest request) {
		String staffName = (String) request.getSession().getAttribute("staffName");
		System.out.println("stsffName="+staffName);
		String sql = "select * from staff where staffName='"+staffName+"'";
		StaffDAOImpl staffDAOImpl = new StaffDAOImpl();
		List<Staff> staff= staffDAOImpl.findStaff(sql);
		request.setAttribute("staff", staff);
		return "editUser";
		
	}
	@RequestMapping(value="editUserAction",method=RequestMethod.POST)
	public String editUser(int staffId,String staffPsw,HttpServletRequest request) {
		
		System.out.println("staffId="+staffId+",staffPsw="+staffPsw);
		String sql = "update staff  set staffpsw ='"+staffPsw+"'where staffId='"+staffId+"'";
		StaffDAOImpl staffDAOImpl = new StaffDAOImpl();
		String message;
		if(staffDAOImpl.updateStaff(sql)) {
			message = "密码修改成功！";  
		}else {
			message = "密码修改失败！";  			
		}
		request.getSession().setAttribute("mes", message); 
		return "index";
		
	}
}
